package edu.zut.cs.software.perfect.grade.service.impl;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.zut.cs.software.perfect.base.service.impl.GenericTreeManagerImpl;
import edu.zut.cs.software.perfect.course.domain.CourseCategory;
import edu.zut.cs.software.perfect.grade.dao.CourseGradeDao;
import edu.zut.cs.software.perfect.grade.domain.CourseGrade;
import edu.zut.cs.software.perfect.grade.domain.StudentGrade;
import edu.zut.cs.software.perfect.grade.service.CourseGradeManager;

/**
 * @ClassName CourseGradeManagerImpl
 * @Description TODO
 * @Author zhangwenkai
 * @Date 2020年5月29日 下午11:02:33
 * @Version 1.0
 */
@Service(value = "CourseGradeManager")
@Transactional 
public class CourseGradeManagerImpl extends GenericTreeManagerImpl<CourseGrade,Long> implements CourseGradeManager {

	CourseGradeDao courseGradeDao;
	
	@Autowired
	public void setCourseGradeDao(CourseGradeDao courseGradeDao) {
		this.courseGradeDao = courseGradeDao;
		this.dao = courseGradeDao;
		this.treeDao = courseGradeDao;
	}


	@Override
	public List<CourseGrade> findAll() {
		
		return (List<CourseGrade>)this.dao.findAll();
	}


	@Override
	public Optional<CourseGrade> findByCourseId(Long courseId) {
		
		Optional<CourseGrade> result = this.dao.findById(courseId);
		return result;
	}


	@Override
	public Boolean deleteById(Long courseId) {
		Optional<CourseGrade> courseGrade = this.dao.findById(courseId);
		if(courseGrade.equals(Optional.empty())) {
			return false;
		}else {
			this.dao.delete(courseGrade.get());
			return true;
		}
	}
	
	
	
	
}
